package com.burstly.lib.component.networkcomponent.burstly.html.ormma;

import android.content.Context;
import android.content.IntentFilter;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import android.webkit.URLUtil;
import com.burstly.lib.component.networkcomponent.burstly.html.ormma.util.OrmmaConfigurationBroadcastReceiver;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;

public class OrmmaDisplayController extends OrmmaController
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = "OrmmaDisplayController";
  private OrmmaConfigurationBroadcastReceiver mBroadCastReceiver;
  private float mDensity;
  private int mMaxHeight = -1;
  private boolean mMaxSizeSet = false;
  private int mMaxWidth = -1;
  private WindowManager mWindowManager;

  public OrmmaDisplayController(OrmmaView paramOrmmaView, Context paramContext)
  {
    super(paramOrmmaView, paramContext);
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    this.mWindowManager = ((WindowManager)paramContext.getSystemService("window"));
    this.mWindowManager.getDefaultDisplay().getMetrics(localDisplayMetrics);
    this.mDensity = localDisplayMetrics.density;
  }

  private void getDeviceDimensions(OrmmaController.Dimensions paramDimensions)
  {
    if (notLayoutParams(paramDimensions.width))
      paramDimensions.width = ((int)(paramDimensions.width * this.mDensity));
    if (notLayoutParams(paramDimensions.height))
      paramDimensions.height = ((int)(paramDimensions.height * this.mDensity));
    paramDimensions.x = ((int)(paramDimensions.x * this.mDensity));
    paramDimensions.y = ((int)(paramDimensions.y * this.mDensity));
    if ((paramDimensions.height < 0) && (notLayoutParams(paramDimensions.height)))
      paramDimensions.height = this.mOrmmaView.getHeight();
    if ((paramDimensions.width < 0) && (notLayoutParams(paramDimensions.width)))
      paramDimensions.width = this.mOrmmaView.getWidth();
    int[] arrayOfInt = new int[2];
    this.mOrmmaView.getLocationInWindow(arrayOfInt);
    if (paramDimensions.x < 0)
      paramDimensions.x = arrayOfInt[0];
    if (paramDimensions.y < 0)
      paramDimensions.y = (0 + arrayOfInt[1]);
  }

  private static boolean notLayoutParams(int paramInt)
  {
    return (paramInt != Utils.getFillparentValue()) && (paramInt != -1) && (paramInt != -2);
  }

  private static void overrideDimensions(OrmmaController.Dimensions paramDimensions, OrmmaController.Properties paramProperties)
  {
    int i = Utils.getFillparentValue();
    if (paramProperties.height != 0)
      paramDimensions.height = paramProperties.height;
    do
      while (paramProperties.width != 0)
      {
        paramDimensions.width = paramProperties.width;
        return;
        if (paramDimensions.height == -1)
          paramDimensions.height = i;
      }
    while (paramDimensions.width != -1);
    paramDimensions.width = i;
  }

  @JavascriptInterface
  public void close()
  {
    LOG.logDebug("OrmmaDisplayController", "close", new Object[0]);
    this.mOrmmaView.close();
  }

  @JavascriptInterface
  public String dimensions()
  {
    return "{ \"top\" :" + (int)(this.mOrmmaView.getTop() / this.mDensity) + ",\"left\" :" + (int)(this.mOrmmaView.getLeft() / this.mDensity) + ",\"bottom\" :" + (int)(this.mOrmmaView.getBottom() / this.mDensity) + ",\"right\" :" + (int)(this.mOrmmaView.getRight() / this.mDensity) + "}";
  }

  // ERROR //
  @JavascriptInterface
  public void expand(String paramString1, String paramString2, String paramString3)
  {
    // Byte code:
    //   0: getstatic 31	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaDisplayController:LOG	Lcom/burstly/lib/util/LoggerExt;
    //   3: ldc 10
    //   5: ldc 174
    //   7: iconst_3
    //   8: anewarray 125	java/lang/Object
    //   11: dup
    //   12: iconst_0
    //   13: aload_1
    //   14: aastore
    //   15: dup
    //   16: iconst_1
    //   17: aload_2
    //   18: aastore
    //   19: dup
    //   20: iconst_2
    //   21: aload_3
    //   22: aastore
    //   23: invokevirtual 129	com/burstly/lib/util/LoggerExt:logDebug	(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    //   26: pop
    //   27: new 76	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Dimensions
    //   30: dup
    //   31: invokespecial 175	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Dimensions:<init>	()V
    //   34: astore 5
    //   36: aload 5
    //   38: iconst_0
    //   39: putfield 89	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Dimensions:x	I
    //   42: aload 5
    //   44: iconst_0
    //   45: putfield 92	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Dimensions:y	I
    //   48: aload_1
    //   49: ldc 177
    //   51: invokevirtual 183	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   54: ifne +21 -> 75
    //   57: new 185	org/json/JSONObject
    //   60: dup
    //   61: aload_1
    //   62: invokespecial 188	org/json/JSONObject:<init>	(Ljava/lang/String;)V
    //   65: ldc 76
    //   67: invokestatic 192	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaDisplayController:getFromJSON	(Lorg/json/JSONObject;Ljava/lang/Class;)Ljava/lang/Object;
    //   70: checkcast 76	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Dimensions
    //   73: astore 5
    //   75: new 185	org/json/JSONObject
    //   78: dup
    //   79: aload_3
    //   80: ldc 194
    //   82: ldc 196
    //   84: invokevirtual 200	java/lang/String:replace	(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;
    //   87: invokespecial 188	org/json/JSONObject:<init>	(Ljava/lang/String;)V
    //   90: astore 7
    //   92: aload 7
    //   94: ldc 202
    //   96: invokevirtual 205	org/json/JSONObject:get	(Ljava/lang/String;)Ljava/lang/Object;
    //   99: astore 12
    //   101: aload 12
    //   103: astore 9
    //   105: aload 9
    //   107: ifnull +42 -> 149
    //   110: aload 9
    //   112: instanceof 179
    //   115: ifeq +34 -> 149
    //   118: aload 7
    //   120: ldc 202
    //   122: new 135	java/lang/StringBuilder
    //   125: dup
    //   126: invokespecial 136	java/lang/StringBuilder:<init>	()V
    //   129: ldc 194
    //   131: invokevirtual 142	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   134: aload 9
    //   136: checkcast 179	java/lang/String
    //   139: invokevirtual 142	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   142: invokevirtual 168	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   145: invokevirtual 209	org/json/JSONObject:put	(Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;
    //   148: pop
    //   149: aload 7
    //   151: ldc 118
    //   153: invokestatic 192	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaDisplayController:getFromJSON	(Lorg/json/JSONObject;Ljava/lang/Class;)Ljava/lang/Object;
    //   156: checkcast 118	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Properties
    //   159: astore 10
    //   161: aload 5
    //   163: aload 10
    //   165: invokestatic 211	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaDisplayController:overrideDimensions	(Lcom/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Dimensions;Lcom/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Properties;)V
    //   168: aload_0
    //   169: aload 5
    //   171: invokespecial 213	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaDisplayController:getDeviceDimensions	(Lcom/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Dimensions;)V
    //   174: aload_0
    //   175: getfield 96	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaDisplayController:mOrmmaView	Lcom/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaView;
    //   178: aload 5
    //   180: aload_2
    //   181: aload 10
    //   183: invokevirtual 216	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaView:expand	(Lcom/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Dimensions;Ljava/lang/String;Lcom/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaController$Properties;)V
    //   186: return
    //   187: astore 6
    //   189: getstatic 31	com/burstly/lib/component/networkcomponent/burstly/html/ormma/OrmmaDisplayController:LOG	Lcom/burstly/lib/util/LoggerExt;
    //   192: ldc 10
    //   194: aload 6
    //   196: invokevirtual 220	com/burstly/lib/util/LoggerExt:logThrowable	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   199: return
    //   200: astore 8
    //   202: aconst_null
    //   203: astore 9
    //   205: goto -100 -> 105
    //
    // Exception table:
    //   from	to	target	type
    //   48	75	187	java/lang/Exception
    //   75	92	187	java/lang/Exception
    //   110	149	187	java/lang/Exception
    //   149	186	187	java/lang/Exception
    //   92	101	200	java/lang/Exception
  }

  @JavascriptInterface
  public String getMaxSize()
  {
    if (this.mMaxSizeSet)
      return "{ width: " + this.mMaxWidth + ", height: " + this.mMaxHeight + "}";
    return getScreenSize();
  }

  @JavascriptInterface
  public int getOrientation()
  {
    int i = this.mWindowManager.getDefaultDisplay().getOrientation();
    int j = -1;
    switch (i)
    {
    default:
    case 0:
    case 1:
    case 2:
    case 3:
    }
    while (true)
    {
      LoggerExt localLoggerExt = LOG;
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = Integer.valueOf(j);
      localLoggerExt.logDebug("OrmmaDisplayController", "getOrientation: {0}", arrayOfObject);
      return j;
      j = 0;
      continue;
      j = 90;
      continue;
      j = 180;
      continue;
      j = 270;
    }
  }

  @JavascriptInterface
  public String getScreenSize()
  {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    this.mWindowManager.getDefaultDisplay().getMetrics(localDisplayMetrics);
    return "{ width: " + (int)(localDisplayMetrics.widthPixels / localDisplayMetrics.density) + ", height: " + (int)(localDisplayMetrics.heightPixels / localDisplayMetrics.density) + "}";
  }

  @JavascriptInterface
  public String getSize()
  {
    return this.mOrmmaView.getSize();
  }

  @JavascriptInterface
  public void hide()
  {
    LOG.logDebug("OrmmaDisplayController", "hide", new Object[0]);
    this.mOrmmaView.hide();
  }

  @JavascriptInterface
  public boolean isViewable()
  {
    return this.mOrmmaView.isShown();
  }

  public void logHTML(String paramString)
  {
    LOG.logDebug("OrmmaDisplayController", paramString, new Object[0]);
  }

  public void onOrientationChanged(int paramInt)
  {
    String str = "window.ormmaview.fireChangeEvent({ orientation: " + paramInt + "});";
    LOG.logDebug("OrmmaDisplayController", str, new Object[0]);
    this.mOrmmaView.injectJavaScript(str);
  }

  @JavascriptInterface
  public void open(String paramString, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3)
  {
    LoggerExt localLoggerExt = LOG;
    Object[] arrayOfObject = new Object[4];
    arrayOfObject[0] = paramString;
    arrayOfObject[1] = Boolean.valueOf(paramBoolean1);
    arrayOfObject[2] = Boolean.valueOf(paramBoolean2);
    arrayOfObject[3] = Boolean.valueOf(paramBoolean3);
    localLoggerExt.logDebug("OrmmaDisplayController", "open: url: {0} back: {1} forward: {2} refresh: {3}", arrayOfObject);
    if (!URLUtil.isValidUrl(paramString))
    {
      this.mOrmmaView.raiseError("Invalid url", "open");
      return;
    }
    this.mOrmmaView.open(paramString, paramBoolean1, paramBoolean2, paramBoolean3);
  }

  @JavascriptInterface
  public void playAudio(String paramString1, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4, String paramString2, String paramString3)
  {
    LoggerExt localLoggerExt = LOG;
    Object[] arrayOfObject = new Object[7];
    arrayOfObject[0] = paramString1;
    arrayOfObject[1] = Boolean.valueOf(paramBoolean1);
    arrayOfObject[2] = Boolean.valueOf(paramBoolean2);
    arrayOfObject[3] = Boolean.valueOf(paramBoolean3);
    arrayOfObject[4] = Boolean.valueOf(paramBoolean4);
    arrayOfObject[5] = paramString2;
    arrayOfObject[6] = paramString3;
    localLoggerExt.logDebug("OrmmaDisplayController", "playAudio: url: {0} autoPlay: {1} controls: {2} loop: {3} position: {4} startStyle: {5} stopStyle: {6}", arrayOfObject);
    if (!URLUtil.isValidUrl(paramString1))
    {
      this.mOrmmaView.raiseError("Invalid url", "playAudio");
      return;
    }
    this.mOrmmaView.playAudio(paramString1, paramBoolean1, paramBoolean2, paramBoolean3, paramBoolean4, paramString2, paramString3);
  }

  @JavascriptInterface
  public void playVideo(String paramString1, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4, int[] paramArrayOfInt, String paramString2, String paramString3)
  {
    LoggerExt localLoggerExt = LOG;
    Object[] arrayOfObject = new Object[11];
    arrayOfObject[0] = paramString1;
    arrayOfObject[1] = Boolean.valueOf(paramBoolean1);
    arrayOfObject[2] = Boolean.valueOf(paramBoolean2);
    arrayOfObject[3] = Boolean.valueOf(paramBoolean3);
    arrayOfObject[4] = Boolean.valueOf(paramBoolean4);
    arrayOfObject[5] = Integer.valueOf(paramArrayOfInt[0]);
    arrayOfObject[6] = Integer.valueOf(paramArrayOfInt[1]);
    arrayOfObject[7] = Integer.valueOf(paramArrayOfInt[2]);
    arrayOfObject[8] = Integer.valueOf(paramArrayOfInt[3]);
    arrayOfObject[9] = paramString2;
    arrayOfObject[10] = paramString3;
    localLoggerExt.logDebug("OrmmaDisplayController", "playVideo: url: {0} audioMuted: {1} autoPlay: {2} controls: {3} loop: {4} x: {5} y: {6} width: {7} height: {8} startStyle: {9} stopStyle: {10}", arrayOfObject);
    int i = paramArrayOfInt[0];
    OrmmaController.Dimensions localDimensions = null;
    if (i != -1)
    {
      localDimensions = new OrmmaController.Dimensions();
      localDimensions.x = paramArrayOfInt[0];
      localDimensions.y = paramArrayOfInt[1];
      localDimensions.width = paramArrayOfInt[2];
      localDimensions.height = paramArrayOfInt[3];
      getDeviceDimensions(localDimensions);
    }
    if (!URLUtil.isValidUrl(paramString1))
    {
      this.mOrmmaView.raiseError("Invalid url", "playVideo");
      return;
    }
    this.mOrmmaView.playVideo(paramString1, paramBoolean1, paramBoolean2, paramBoolean3, paramBoolean4, localDimensions, paramString2, paramString3);
  }

  @JavascriptInterface
  public void resize(int paramInt1, int paramInt2)
  {
    LoggerExt localLoggerExt = LOG;
    Object[] arrayOfObject = new Object[2];
    arrayOfObject[0] = Integer.valueOf(paramInt1);
    arrayOfObject[1] = Integer.valueOf(paramInt2);
    localLoggerExt.logDebug("OrmmaDisplayController", "resize: width: {0} height: {1}", arrayOfObject);
    if (((this.mMaxHeight > 0) && (paramInt2 > this.mMaxHeight)) || ((this.mMaxWidth > 0) && (paramInt1 > this.mMaxWidth)))
    {
      this.mOrmmaView.raiseError("Maximum size exceeded", "resize");
      return;
    }
    this.mOrmmaView.resize((int)(this.mDensity * paramInt1), (int)(this.mDensity * paramInt2));
  }

  @JavascriptInterface
  public void setMaxSize(int paramInt1, int paramInt2)
  {
    this.mMaxSizeSet = true;
    this.mMaxWidth = paramInt1;
    this.mMaxHeight = paramInt2;
  }

  @JavascriptInterface
  public void show()
  {
    LOG.logDebug("OrmmaDisplayController", "show", new Object[0]);
    this.mOrmmaView.show();
  }

  public void startConfigurationListener()
  {
    try
    {
      if (this.mBroadCastReceiver == null)
        this.mBroadCastReceiver = new OrmmaConfigurationBroadcastReceiver(this);
      this.mContext.registerReceiver(this.mBroadCastReceiver, new IntentFilter("android.intent.action.CONFIGURATION_CHANGED"));
      return;
    }
    catch (Exception localException)
    {
      LOG.logThrowable("OrmmaDisplayController", localException);
    }
  }

  public void stopAllListeners()
  {
    stopConfigurationListener();
    this.mBroadCastReceiver = null;
  }

  public void stopConfigurationListener()
  {
    if (this.mBroadCastReceiver != null);
    try
    {
      this.mContext.unregisterReceiver(this.mBroadCastReceiver);
      this.mBroadCastReceiver = null;
      return;
    }
    catch (Exception localException)
    {
      LOG.logThrowable("OrmmaDisplayController", localException);
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.ormma.OrmmaDisplayController
 * JD-Core Version:    0.6.2
 */